<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="../../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!doctype html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=emulateIE7"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta charset="utf-8">
    <link rel="stylesheet" href="${ctx}/css/sapar.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/common.css"/>
    <script type="text/javascript" src="${ctx}/js/jquery.js"></script>
    <script type="text/javascript" src="${ctx}/js/sapar.js"></script>
    <script type="text/javascript" src="${ctx}/js/WdatePicker.js"></script>
    <script type="text/javascript" src="${ctx}/assets/layer/layer.js"></script>

    <script type="text/javascript" src="${ctx}/js/mask.js"></script>
    <title>编辑器械</title>
    <style type="text/css">
        .kv-item label {
            width: 90px;
        }

        .dataSel .iselect-wrapper {
            float: left;
            margin-right: 5px;
            width: 158px;
        }

        .dataSel .iselect-wrapper .iselect {
            width: 158px;
        }

        #mc {
            width: 100px;
        }
    </style>
</head>

<body>
<div id="mask" class="mask"></div>
<div id="saper-container">
    <div id="saper-hd"></div>
    <div id="saper-bd">
        <div class="subfiled clearfix">
            <h2>编辑器械</h2>
        </div>
        <div class="subfiled-content">
            <form class="saper-form" id="dataForm">
                <div class="kv-item clearfix">
                    <label ><span class="impInfo">*</span>器械名称：</label>
                    <div class="kv-item-content">
                        <input type="text" placeholder="器械名称" class="txt_required" name="productName" id="productName"
                               value="${product.productName}"
                               onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
                    </div>
                </div>
                <div class="kv-item clearfix">
                    <label >别名：</label>
                    <div class="kv-item-content">
                        <input type="text" placeholder="别名" id="productMark" name="productMark"
                               value="${product.productMark}">
                        <%--<textarea cols="50" rows="10" id="productMark" name="productMark" value="product.productMark">${product.productMark}</textarea>--%>
                    </div>
                </div>

                <div class="kv-item dataSel clearfix">
                    <label ><span class="impInfo">*</span>器械类别：</label>
                    <div class="kv-item-content">
                        <select name="protypeRefid2" id="protypeRefid2" onchange="hiddenDiv()">
                            <option value="">选择类型</option>
                            <c:if test="${productTypeList !=null }">
                                <c:forEach items="${productTypeList }" var="td">
                                    <option
                                            <c:if test="${product.protypeRefid2==td.dictId}">selected='selected'</c:if>
                                            value="${td.dictId}">${td.dictName}</option>
                                </c:forEach>
                            </c:if>
                        </select>
                    </div>
                </div>

                <div style="display: none" class="kv-item dataSel clearfix" id="linchuang">
                    <label >所属临床科室：</label>
                    <div class="kv-item-content">
                        <select name="protypeRefid3" id="protypeRefid3">
                            <option value="">选择科室</option>
                            <c:if test="${tbDepartments !=null }">
                                <c:forEach items="${tbDepartments }" var="td">
                                    <option
                                            <c:if test="${product.protypeRefid3==td.departmentId}">selected='selected'</c:if>
                                            value="${td.departmentId}">${td.departmentName}</option>
                                </c:forEach>
                            </c:if>
                        </select>
                    </div>
                </div>

                <div class="kv-item clearfix">
                    <label >器械简码：</label>
                    <div class="kv-item-content">
                        <input type="text" placeholder="器械简码" class="txt_required" name="productCode" id="productCode"
                               value="${product.productCode}"
                               onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
                    </div>
                </div>
                <div class="kv-item clearfix">
                    <label >器械规格：</label>
                    <div class="kv-item-content">
                        <input type="text" placeholder="器械规格" class="txt_required" name="productBarcode"
                               id="productBarcode" value="${product.productBarcode}"
                               onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
                    </div>
                </div>

                <div class="kv-item clearfix">
                    <label >器械尺寸 ：</label>
                    <div class="kv-item-content">
                        <input type="text" placeholder="器械尺寸 " class="txt_required" name="productSize" id="productSize"
                               value="${product.productSize}"
                               onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
                    </div>
                </div>
                <div class="kv-item clearfix">
                    <label >器械功能：</label>
                    <div class="kv-item-content">
                        <input type="text" placeholder="器械功能" class="txt_required" name="productFunction"
                               value="${product.productFunction}"
                               onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
                    </div>
                </div>
                <div class="kv-item clearfix">
                    <label >器械价格：</label>
                    <div class="kv-item-content">
                        <input type="text" placeholder="器械价格" class="txt_required" name="productPrice"
                               value="${product.productPrice}"
                               onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
                    </div>
                </div>
                <div class="kv-item clearfix">
                    <label >器械编码：</label>
                    <div class="kv-item-content">
                        <input type="text" placeholder="器械编码" class="txt_required" name="productNo" id="productNo"
                               value="${product.productNo}"
                               onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
                    </div>
                </div>
                <%--<div class="kv-item clearfix">--%>
                    <%--<label id="mc"><span class="impInfo">*</span>器械外部编码：</label>--%>
                    <%--<div class="kv-item-content">--%>
                        <%--<input type="text" placeholder="器械外部编码" class="txt_required" name="productRefcode"--%>
                               <%--value="${product.productRefcode}"--%>
                               <%--onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">--%>
                    <%--</div>--%>
                <%--</div>--%>

                <div class="kv-item dataSel clearfix">
                    <label >器械分类：</label>
                    <div class="kv-item-content">
                        <select name="protypeId" id="protypeId">
                            <option value="">选择状态</option>
                            <c:if test="${proTypelist !=null }">
                                <c:forEach items="${proTypelist }" var="td">
                                    <option
                                            <c:if test="${product.protypeId==td.dictId}">selected='selected'</c:if>
                                            value="${td.dictId}">${td.dictName}</option>
                                </c:forEach>
                            </c:if>
                        </select>
                    </div>
                </div>

                <div class="kv-item clearfix">
                    <label >器械图片 ：</label>
                    <div class="kv-item-content">
                        <input type="hidden" name="productPic" id="productPic" value="${product.productPic}"/>
                        <input type="file" name="upPicFile" id="upPicFile" value="">
                        <input type="button" id="uploadPic" value="上传"/>
                    </div>
                </div>

                <%-- <div class="kv-item dataSel clearfix">
                    <label id="mc">是否厂家器械：</label>
                    <div class="kv-item-content">
                        <select name="productState">
                            <option value="1" <c:if test="${product.productState==1}">selected="selected"</c:if>>可用</option>
                            <option value="0" <c:if test="${product.productState==0}">selected="selected"</c:if>>不可用</option>
                        </select>
                    </div>
                </div> --%>
                <div class="kv-item dataSel clearfix">
                    <label >器械状态：</label>
                    <div class="kv-item-content">
                        <select name="productState">
                            <option value="1" <c:if test="${product.productState==1}">selected="selected"</c:if>>可用
                            </option>
                            <option value="0" <c:if test="${product.productState==0}">selected="selected"</c:if>>不可用
                            </option>
                        </select>
                    </div>
                </div>

                <div class="buttons">
                    <a href="javascript:;" class="sapar-btn sapar-btn-recom">确定</a>
                    <input type="hidden" name="productId" id="productId" value="${product.productId}"/>
                </div>
            </form>
        </div>
    </div>
    <div id="saper-ft"></div>
</div>


<script src="${ctx}/js/ajaxfileupload.js"></script>
<script type="text/javascript">

    function hiddenDiv() {
        var selvalue = $("#protypeRefid2").val();
        if (selvalue ==212) {
            $("#linchuang").show("slow");
        } else {
            $("#linchuang").hide("hidden");

        }
    }

    $(function () {
        $(".sapar-btn-recom").click(function () {
            var index = parent.layer.getFrameIndex(window.name);
            var btn = true;
            if (btn) {
                showMask();
                $.ajax({
                    type: "POST",
                    url: "${ctx}/product/productSave.do",
                    data: $('#dataForm').serialize(),// 你的formid
                    error: function (request) {
                        layer.alert("网络故障，请稍后再试!");
                    },
                    success: function (data) {
                        $("#mask").hide();
                        if (data.status == "true") {
                            var product = data.product;
                            layer.alert("保存成功", function () {
                                parent.layer.close(index);
                                parent.callbackData(product);

                            });
                        } else {
                            layer.msg(data.msg);
                        }
                    }
                });
            }
        });

        $("#uploadPic").click(function () {
            if ($("#upPicFile").val() == '') {
                layer.msg("请选择图片");
                return false;
            }
            ajaxFileUpload();
        });



        $('#productName').change(function () {
            var departmentName = $('#productName').val();
            /*速记码生成器  */
            $.ajax({
                url: "${ctx}/eng/cn2en.do?prefix=a&msg=" + departmentName,
                dateType: "json",
                type: "post",
                success: function (data) {
                    if (data.status == "true") {
                        console.log(data.msg);
                        $("#productCode").val(data.msg);
                    } else {
                        layer.msg("速记码转换异常");
                    }
                }
            });
        });
        
        function ajaxFileUpload() {
            $.ajaxFileUpload
            (
                {
                    url: '${ctx}/upload/filesUploadPics.do', //用于文件上传的服务器端请求地址
                    secureuri: false, //是否需要安全协议，一般设置为false
                    fileElementId: 'upPicFile', //文件上传域的ID
                    dataType: 'json', //返回值类型 一般设置为json
                    success: function (data, status)  //服务器成功响应处理函数
                    {
                        var msg = data.message;
                        if (data.error == 1) {
                            $("#productPic").val(msg);
                            layer.alert('上传成功', {
                                skin: 'layui-layer-lan'
                                , closeBtn: 0
                                , shift: 4 //动画类型
                            });
                        } else {
                            layer.alert('上传失败,' + msg, {
                                skin: 'layui-layer-lan'
                                , closeBtn: 0
                                , shift: 4 //动画类型
                            });
                        }

                    },
                    error: function (data, status, e)//服务器响应失败处理函数
                    {
                        alert("上传失败");
                    }
                }
            )
            return false;
        }

    });
    $('select').iSelect();
</script>
</body>
</html>